<?php

namespace app\common\model;

/**
 * [Friends  好友表]
 * @author [C。]
 * @return html
 */
class Friends extends Base
{
    protected $name = 'friends';
    /**
     * 获取单条信息
     */
    public function getOne($map1,$map2=[])
    {
        $result = $this->where($map1)->whereOr($map2)->find();
        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getByConditon($map, $from=0, $size = 5,$field='*')
    {
        $order = ['id' => 'desc'];
        $result =  $this->field($field)
            ->where($map)
            ->limit($from, $size)
            ->order($order)
            ->select();

        return $result;
    }

    /**
     * 根据条件来获取列表的数据的总数
     * @param array $param
     */
    public function getCountByCondition($map = []) {
        $result =  $this->where($map)->count();
        return $result;
    }
    /**
     * 根据搜索条件获取列表信息
     */
    public function getList($map, $from=0, $size = 5,$field='*')
    {
        $order = ['id' => 'desc'];
        $join1 = [
            ['app_member am1','am1.id = f.friend_id'],
        ];
        $join2 = [
            ['app_member am2','am2.id = f.memid'],
        ];
        $result =  $this->field($field)
            ->alias('f')
            ->join($join1)
            ->join($join2)
            ->where($map)
            ->limit($from, $size)
            ->order($order)
            ->select();

        return $result;
    }
}